<script language="javascript">
var ajax1=new sack();
function getVehicleCurrentStatus(devImei)
{
	var wrapperId 	=	'#content';
	var postFile	=	'deviceStatus.php';
	$.post(postFile, { devImei: devImei}, function(data){$(wrapperId).slideUp('2000',function(){$(this).html(data).slideDown();}).html();});
	//setTimeout('getVehicleCurrentStatus('+devImei+')', 20000);
}
/*$(function() {
$(".editable_textarea").editable("ajax_server.php", { 
  indicator : "<img src='../../imgages/indicator.gif'>",
  submitdata: { _method: "put" },
  submit : 'OK',
  cancel : 'cancel',
  tooltip   : "Click to edit odometer"
});
});*/

</script>
<table class="gridform_final" >
<?php
	$sql = "SELECT * FROM tb_deviceinfo,tb_client_subscription,tb_clientinfo WHERE tcs_isActive = 1 AND tcs_deviceId = di_id AND di_status = 1 AND di_clientId=ci_id AND ci_id=".$_SESSION[clientID]." AND di_id = ".$_POST[txtDeviceId];
	$rows = $db->query($sql);
	
   	$record = $db->fetch_array($rows);
//		print_r($record);
		if($record[di_deviceName])
			$devName = $record[di_deviceName];
		else
			$devName = $record[di_deviceId];
		
		$renewDate = date("d-m-Y",strtotime("-1 days ".$record[tcs_renewalDateTo]));
		if(strtotime(date("d-m-Y")) <= strtotime($renewDate))
		{
			$expStatus = "<span>Monthly subscription will expire on ".$renewDate."</span>";
			$vehiStatus = 1;
		}
		else
		{
			$expStatus = "<span style='color:red'>Monthly subscription expired </span>";
			$vehiStatus = 0;
		}
		
		$getInsurance = "select * from tb_device_insurance_info where tdii_deviceId = ".$record[di_id];
		$resInsurance = $db->query($getInsurance);
		if($db->affected_rows >0)
		{
			$fetInsurance = $db->fetch_array($resInsurance);
			$insExpDate ="<span>Insurance will expire on ". $fetInsurance[tdii_policyExpDate]."</span>";
		}
		else
		{
			$insExpDate ="Nil";
		}
		if($record[di_deviceModel] > 0)
		{
			$sql1 = "SELECT * FROM tb_device_model WHERE id = ".$record[di_deviceModel];
			$rows1 = $db->query($sql1);
			if($db->affected_rows > 0)
			{
				$deviceModelRecord = $db->fetch_array($rows1);
				$devModel = $deviceModelRecord[tdm_aliasName];
			}			
		}else $devModel = "Not Selected";
		
	?>
    		<tr>
            <td width="15%" style="border:none; vertical-align:top;">
            	<table width="100%">
                  <tr>
                    <td style="text-align:center"><img src="unit_img/<?php echo $record[di_deviceImg];?>" width="105" height="105" title="<?php echo ucfirst($devName);?>" alt="<?php echo ucfirst($devName);?>" /></td>
                  </tr>
                 <!-- <tr>
                    <td align="right"><img src="../../images/edit.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $record[di_id];?>','<?php echo $_SESSION[clientID];?>','?ch=addClientDevice')" /></td>
                  </tr>-->
            	</table>
            </td>
            <td valign="top" style="border:0; vertical-align:top; ">
            <table width="100%" class="grid_table">
                  <tr>
                    <td width="15%"><span class="detail_txt">Device Id :</span></td><td width="15%"><?php echo $record[di_deviceId];?></td>
                    <td width="15%"><span class="detail_txt">Device Name :</span></td><td width="15%"><?php echo ucfirst($devName);?></td>
                     <td width="15%"><span class="detail_txt">IMEI :</span></td><td><?php echo $record[di_imeiId];?></td>
                  </tr>
                  <tr>                   
                    <td><span class="detail_txt">Mobile :</span></td><td><?php echo $record[di_mobileNo];?></td>
                    <td><span class="detail_txt">Model :</span></td><td><?php echo ucfirst($devModel);?></td>
                    <td><span class="detail_txt">Odometer</span></td><td><a class="editable_textarea" id="<?php echo "odo_".$record[di_imeiId];?>"><?php echo $record[di_odoMeter];?></a></td>
                    </tr>
                  <tr>                    
                    <td><span class="detail_txt">Map Icon</span></td><td><img src="unit_img/<?php echo $record[di_mapIcon];?>" width="32" height="32" title="<?php echo ucfirst($devName);?>" alt="<?php echo ucfirst($devName);?>" /></td><td colspan="4">&nbsp;</td>
                  </tr>
                  <!--<tr>
                  	<td colspan="6">
                    	<strong>Port Details :</strong>
                    </td>
                  </tr>
                  <tr>
                  	<td colspan="6">
                    	<table width="100%">
                        	<tr>
                            	<th>Fuel</th><th>A/C</th><th>Ignition</th><th>Sos</th><th>Engine</th>
                            </tr>
                            <tr>
                            	<td><?php echo $record[di_Fuelport];?></td><td><?php echo $record[di_Acport];?></td><td><?php echo $record[di_Ignitionport];?></td><td><?php echo $record[di_Sosport];?></td><td><?php echo $record[di_Engineport];?></td>
                            </tr>
                        </table>
                    </td>
                  </tr>-->
                  <?php if($vehiStatus == 1) { ?>
              	  <tr>
                        <td align="left" valign="middle" bgcolor="#FFFFFF"><span class="detail_txt">Current Status </span>
                        <img src="images/refresh.png" style="cursor:pointer;" border="0" onclick="getVehicleCurrentStatus('<?php echo $record[di_imeiId];?>');" />
                        </td>
                        <td colspan="5" height="100px">
                        <div id="content">Loading...
						<script language="javascript">
							getVehicleCurrentStatus('<?php echo $record[di_imeiId]."#".$record[di_odoMeter];?>');
						</script>
                        </div>
                  </tr>
                  <?php } ?>
                  <tr>
                        <td align="left"><span class="detail_txt">Subscription Status : </span></td><td colspan="5"><?php echo $expStatus;?></td>
                  </tr>
                  
             </table>
            </td>
          </tr>  
    	

    <?php
   ?>
</table>
<form name="formpagination" id="formpagination" action="#" method="post">
  <input type="hidden" name="pn" id="pn" value="<?php if(isset($_POST[pn])) echo $_POST[pn]; else echo '1'; ?>" />
  <input type="hidden" name="nr" id="nr" value="<?php echo $_POST[nr]?>" />
  <input type="hidden" name="pageSelect" value="" />
</form>
<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtDeviceId" id="txtDeviceId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
</form>